package com.hoo.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import com.hoo.service.account.AccountService;
import com.hoo.service.account.DictService;
import java.util.List;
import java.util.Map;

@Component
public class InitData implements ApplicationListener<ApplicationEvent> {

  @Value("${ipdb.path}")
  private String ipseekerPath;

  private static Logger logger = LoggerFactory.getLogger(AccountService.class);

  private static boolean isStart = false;

  private static IPSeeker ipSeeker;

  @Autowired
  DictService dictService;
  
  public void onApplicationEvent(ApplicationEvent event) {
    if (!isStart) {
      logger.info("============ begin load global cache ==========");
      isStart = true;
      initData();
      logger.info("============ end load global cache ============");
    }
  }

  public void initData() {
    // init ip
    initIpSeeker();
    // init 卡面值相关字典数据
//    initCardDict();
    // init 省市区
 /*   initRegion();*/
    // init 银行
    /*initBank();*/
    // lazy loading
  }

  private void initBank() {}



  // ---------- ip
  public void initIpSeeker() {
    try {
      ipSeeker = IPSeeker.getInstance(ipseekerPath);
    } catch (Exception e) {
      logger.error(e.getMessage());
    }
  }

  public static IPSeeker getIPSeeker() {
    return ipSeeker;
  }

  // ---------- 省市区
  /*public void initRegion() {
    List<Map<String, Object>> regionsMap = dictService.getRegions();
    Map<Integer, Map<String, Object>> result = Maps.newHashMap();
    for (Map<String, Object> region : regionsMap) {
      result.put((Integer) region.get("id"), region);
    }
    GlobalCache.regionsMap = result;
  }*/
   public static final String getRegionName(int id) {
   return null;
   }
  
   public static final List<Map> getProvinces() {
   return null;
   }
  
   public static final List<Map> getCitiesByProvinceId(int provinceId) {
   return null;
   }
  
   public static final List<Map> getAreasByCityId(int cityId) {
   return null;
   }

}
